package leetcode.p897;

/**
 * @author: trtan
 * @create: 2021-04-25 08:49
 * @description:
 **/
public class IncreasingOrderSearchTree {
    TreeNode nowNode;
    public TreeNode increasingBST(TreeNode root) {
        TreeNode preRoot = new TreeNode(-1);
        nowNode = preRoot;
        dfs(root);
        return preRoot.right;
    }

    void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        dfs(root.left);
        nowNode.right = root;
        root.left = null;
        nowNode = root;
        dfs(root.right);
    }
}
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}